// 题目就是: 给你多组日期,指定相加多少天,然后输出值

#include <iostream>

using namespace std ;

int CheckMonthDay (int year , int month)
{

    int arr [13] = { -1 , 31 , 28 , 31 , 30 , 31 , 30 , 31 , 31 , 30 , 31 , 30 , 31 } ;

    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
    {

        return 29 ;

    }

    return arr [month] ;

}

int main() 
{
    
    int n ;

    cin >> n ;

    for (int i = 0 ; i < n ; i++)
    {

        int year , month , day , add ;
    
        cin >> year >> month >> day >> add ;

        day += add ;

        while (day > CheckMonthDay(year , month))
        {

            day -= CheckMonthDay(year , month) ;

            month++ ;

            if (month > 12)
            {

                month = 1 ;

                year++ ;

            }

        }

        if (month < 10)
        {

            if (day < 10)
            {

                cout << year << "-0" << month << "-0" << day << endl ;

            }

            else 
            {

                cout << year << "-0" << month << "-" << day << endl ;
            
            }

        }
        
        else 
        {

            if (day < 10)
            {

                cout << year << "-" << month << "-0" << day << endl ;

            }

            else 
            {

                cout << year << "-" << month << "-" << day << endl ;
            
            }
        
        }

    }

}